package GUI_Data.User;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
/**
 * The user frame.
 * It's the client window, including connect data, initialize interface and reset interface functions.
 * @author Xiaorun Wang
 * @author Chunxi Lin
 * @author Yibai Jiang
 */
public class UserFrame extends JFrame implements ActionListener, FocusListener {
    private CardLayout frameCard = new CardLayout();
    private JPanel contentPanel = new JPanel(frameCard);

    /**
     * The generator of the user frame.
     */
    public UserFrame() {
        init();

        setResizable(false);
        setUndecorated(true);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    /**
     * The init method of the whole frame.
     * By using the card layout, the page can be refreshed and invoked at frame initialization and page reset
     */
    public void init() {
        JPanel nowFrame = new JPanel();
        contentPanel.add("now frame", nowFrame);
        setContentPane(contentPanel);

        SetDimension dimension = new SetDimension();

        setTitle("Welcome!");
        setExtendedState(JFrame.MAXIMIZED_BOTH);

        CardLayout cardLayout = new CardLayout();
        CardLayout login = new CardLayout();

        // initialize all button
        AllButton allButton = new AllButton(this, dimension);
        // initialize all label and text field
        AllLabelAndTextField allLabelAndTextField = new AllLabelAndTextField(this);

        // initialize all panel
        AllPanel allPanel = new AllPanel(nowFrame, dimension, allButton, allLabelAndTextField, cardLayout, login);
        // initialize the actionListener of all buttons.
        allButton.addActionPerform(this, dimension, allPanel, allLabelAndTextField, cardLayout, login);

        // set background image
        //setBackgroundInfo(dimension);
        frameCard.next(contentPanel);

    }

    @Override
    public void actionPerformed(ActionEvent e) {

    }

    @Override
    public void focusGained(FocusEvent e) {

    }

    @Override
    public void focusLost(FocusEvent e) {

    }
}
